package com.hao.proxy.config;

import com.hao.proxy.core.DefaultFilterRule;
import com.hao.proxy.core.FilterRule;


public class ProxyConfig {
	
//	public static final ProxyConfig DEFAULT = new Builder().build();
	
	private final int filterNum;
	private final int minProxyNum;
	private final int spareProxyNum;//备用的代理数量
	private final int verifiedProxyValidateTime;//可用代理验证一轮时间
	private final int unVerifiedProxyValidateTime;//未验证代理验证一轮时间
	private final FilterRule filterRule;
	
	protected ProxyConfig(){
		this(5,5,1,60000,60000,null);
	}
	
	ProxyConfig(int filterNum, int minProxyNum, int spareProxyNum, int verifiedProxyValidateTime, int unVerifiedProxyValidateTime, FilterRule filterRule) {
		super();
		this.filterNum = filterNum;
		this.minProxyNum = minProxyNum;
		this.spareProxyNum = spareProxyNum;
		this.verifiedProxyValidateTime = verifiedProxyValidateTime;
		this.unVerifiedProxyValidateTime = unVerifiedProxyValidateTime;
		this.filterRule = filterRule;
	}

	public int getFilterNum() {
		return filterNum;
	}

	
	public int getMinProxyNum() {
		return minProxyNum;
	}

	
	public int getSpareProxyNum() {
		return spareProxyNum;
	}

	
	public int getVerifiedProxyValidateTime() {
		return verifiedProxyValidateTime;
	}

	
	public int getUnVerifiedProxyValidateTime() {
		return unVerifiedProxyValidateTime;
	}

	
	public FilterRule getFilterRule() {
		return filterRule;
	}
	
	public static ProxyConfig.Builder custom() {
        return new Builder();
    }


	public static class Builder{
		private int filterNum;
		private int minProxyNum;
		private int spareProxyNum;//备用的代理数量
		private int verifiedProxyValidateTime;//可用代理验证一轮时间
		private int unVerifiedProxyValidateTime;//未验证代理验证一轮时间
		private FilterRule filterRule;
		
		Builder() {
			this.filterNum = 5;
			this.minProxyNum = 5;
			this.spareProxyNum = 1;
			this.verifiedProxyValidateTime = 60000;
			this.unVerifiedProxyValidateTime = 60000;
			this.filterRule = DefaultFilterRule.getInstance();
		}

		
		public Builder setFilterNum(int filterNum) {
			this.filterNum = filterNum;
			return this;
		}

		
		public Builder setMinProxyNum(int minProxyNum) {
			this.minProxyNum = minProxyNum;
			return this;
		}

		
		public Builder setSpareProxyNum(int spareProxyNum) {
			this.spareProxyNum = spareProxyNum;
			return this;
		}

		
		public Builder setVerifiedProxyValidateTime(int verifiedProxyValidateTime) {
			this.verifiedProxyValidateTime = verifiedProxyValidateTime;
			return this;
		}

		
		public Builder setUnVerifiedProxyValidateTime(int unVerifiedProxyValidateTime) {
			this.unVerifiedProxyValidateTime = unVerifiedProxyValidateTime;
			return this;
		}

		
		public Builder setFilterRule(FilterRule filterRule) {
			this.filterRule = filterRule;
			return this;
		}
		
		public ProxyConfig build(){
			return new ProxyConfig(filterNum, minProxyNum, spareProxyNum, verifiedProxyValidateTime, unVerifiedProxyValidateTime, filterRule);
		};
	}
}
